package com.atguigu.gmall.order.receiver;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gsy
 * @date 2021年09月14日9:52
 * Description
 */
@Configuration
public class OrderCanelMqConfig {

    //交换机
    @Bean
    public Exchange delayExchange(){
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type","direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,
                "x-delayed-message",true,false,arguments);
    }
    //队列
    @Bean
    public Queue delayQueue(){
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }
    //绑定
    @Bean
    public Binding bindingQueueToExchange(@Qualifier("delayQueue") Queue queue,@Qualifier("delayExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}
